/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023.
 * Description: set rpc's nfs debug info
 * Author: Pang LiYuan
 * Create: 2023-09-15
 */
#include <linux/sunrpc/svc.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/sched.h>
#include "rtos_debuginfo.h"

static u64 rpc_clnt_throttle = 1;

void nfs_set_rpc_clnt_throttle(u64 throttle)
{
	rpc_clnt_throttle = throttle;
}
EXPORT_SYMBOL(nfs_set_rpc_clnt_throttle);

u64 nfs_get_rpc_clnt_throttle(void)
{
	return rpc_clnt_throttle;
}
EXPORT_SYMBOL(nfs_get_rpc_clnt_throttle);

void rpc_update_debuginfo(struct rpc_task *task)
{
	u64 interval;
	interval = get_jiffies_64() - task->start;

	if (!task->tk_msg.rpc_proc->p_debuginfo)
		return;

	if (interval >= rpc_clnt_throttle)
		task->tk_msg.rpc_proc->p_debuginfo->p_cnt++;

	if (interval > task->tk_msg.rpc_proc->p_debuginfo->p_max_time)
		task->tk_msg.rpc_proc->p_debuginfo->p_max_time = interval;

	task->tk_msg.rpc_proc->p_debuginfo->p_time_total += interval;
}
